# 作者: YYJ
# 2025年07月12日14时59分12秒
# 2486249622@qq.com

from threading import Thread, Lock


# g_num = 100
def work1(my_list, lock):
    lock.acquire()
    for i in range(1,4):
        my_list.append(i)
    lock.release()
    print(f"子进程1 my_list={my_list}")


def work2(my_list, lock):
    lock.acquire()
    for i in range(4,7):
        my_list.append(i)
    lock.release()
    print(f"子进程2 my_list={my_list}")


if __name__ == '__main__':
    my_list = []
    lock_thread = Lock()
    t1 = Thread(target=work1, args=(my_list, lock_thread))
    t2 = Thread(target=work2, args=(my_list, lock_thread))
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print(f"主进程 my_list={my_list}")